using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace whereIsTheDonutGame
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Gate : Microsoft.Xna.Framework.DrawableGameComponent
    {
        private Model gate;
        private ICamera camera;
        int trans = 0;
        
        public void openGate()
        {
            trans = 10;
        }

        public void closeGate()
        {
            trans = 0;
        }
        public Gate(Game game)
            : base(game)
        {

        }


        public override void Initialize()
        {
            camera = (ICamera)Game.Services.GetService(typeof(ICamera));

            base.Initialize();
        }


        public override void Update(GameTime gameTime)
        {
            KeyboardState state = Keyboard.GetState();

            //zu testzwecken
            if (state.IsKeyDown(Keys.K))
            {
                this.openGate();
                
            }
            else if (state.IsKeyDown(Keys.L))
            {
                this.closeGate();
            }
                
                base.Update(gameTime);

        }

    
        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            foreach (ModelMesh mesh in gate.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.View = camera.ViewMatrix;
                    effect.Projection = camera.ProjectionMatrix;
                    effect.World = Matrix.CreateTranslation(new Vector3(0, trans, 0.0f));
                }
                mesh.Draw();
            }
            base.Draw(gameTime);
        }

        protected override void LoadContent()
        {
           gate = this.Game.Content.Load<Model>("box");
        }
    }
}
